<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数组排序</title>
</head>
<body>
<h1>JavaScript数组排序</h1>

<p>sort() 方法按字母顺序对数组进行排序。</p>

<button onclick="myFunction()">排序</button>
<button onclick="myFunction1()">反转排序</button>
<p id="demo"></p>
<p id="demo1"></p>
<script>
  var fruits = ["Orange","Banana","Apple","Mango"];
  document.getElementById("demo").innerHTML = fruits;

  function myFunction(){
    fruits.sort();
    document.getElementById("demo").innerHTML = fruits;
  }
  function myFunction1(){
    //反转排序
    fruits.reverse();
    document.getElementById("demo1").innerHTML = fruits;
  }
</script>
</body>
</html>